package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.TbGoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class TbGoodsController {

    @DubboReference
    private TbGoodsService tbGoodsService;

    @RequestMapping("toGoods")
    public String toGoods(){
        return "/admin/goods";
    }

    @RequestMapping("show")
    @ResponseBody
    public Result show(TbGoods tbGoods){
        List<TbGoods> tbGoods1 = tbGoodsService.selectAll(tbGoods);
        if (tbGoods1 == null) {
            Result.response(ResultEnum.ERROR);
        }
        return Result.response(ResultEnum.SUCCESS).setData(tbGoods1);
    }

    @RequestMapping("pass")
    @ResponseBody
    public Result pass(@RequestParam("ids") Long[] ids){
        boolean b = tbGoodsService.updateByPass(ids);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }
        return Result.response(ResultEnum.ERROR);
    }

    @RequestMapping("noPass")
    @ResponseBody
    public Result noPass(@RequestParam("ids") Long[] ids){
        boolean b = tbGoodsService.updateByNoPass(ids);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }
        return Result.response(ResultEnum.ERROR);
    }

    @RequestMapping("deleteGoods")
    @ResponseBody
    public Result deleteGoods(@RequestParam("ids") Long[] ids){
        boolean b = tbGoodsService.deleteBy(ids);
        if (b){
            return Result.response(ResultEnum.SUCCESS);
        }
        return Result.response(ResultEnum.ERROR);
    }

}
